package com.idione.controller;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.idione.activities.R;
import com.idione.util.LogUtil;

public class ShowSignal {

	private Context context;

	private TextView TVTitle;
	private ImageView IVquestionImg;
	private TextView TVargumenText;
	private Button button;

	private Dialog dialog;
	
	public ShowSignal(Context context) {
		this.context = context;
		this.prepareDialog();
	}

	private void prepareDialog() {

		//set up dialog
		dialog = new Dialog(context, R.style.DialogTheme);
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.answer_signal);

		dialog.setCancelable(true);
		dialog.setCanceledOnTouchOutside(false);
		dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;

		//set up title
		TVTitle = (TextView) dialog.findViewById(R.id.LblViewNameSignal);

		//set up imageViewSignal
		IVquestionImg = (ImageView) dialog.findViewById(R.id.ImgViewSignal);

		//set up argumentText
		TVargumenText = (TextView) dialog.findViewById(R.id.LblArgument);

		//set up button
		button = (Button) dialog.findViewById(R.id.BtnOk);
		button.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dialog.dismiss();
			}
		});

		this.setTypeFace();

		dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	}
	
	public void show(String name, int imageSignal, String argument) {
		this.log("show(name, imageSignal, argument)");

		TVTitle.setText(name);
		IVquestionImg.setImageResource(imageSignal);
		TVargumenText.setText(argument);
		//now that the dialog is set up, it's time to show it    
		dialog.show();
	}

	private void setTypeFace() {
		Typeface tfb = LogUtil.getTypeFaceButton(context);
		Typeface tft = LogUtil.getTypeFaceTitle(context);
		Typeface tfp = LogUtil.getTypeFaceParagraph(context);

		TVTitle.setTypeface(tft);
		TVargumenText.setTypeface(tfp);
		button.setTypeface(tfb);
	}

	/*--------------------------------------------------------------------------*
	 * Log																		*
	 *--------------------------------------------------------------------------*/
	private final String LOGTAG = "LogsClass " + this.getClass().getName();
	private void log(String method) {
		if (LogUtil.controllerLog)
			Log.i(LOGTAG, "... method : " + this.getClass().getSimpleName() + "." + method);
	}
}
